package com.traceability.trace.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.traceability.common.annotation.Log;
import com.traceability.common.core.controller.BaseController;
import com.traceability.common.core.domain.AjaxResult;
import com.traceability.common.enums.BusinessType;
import com.traceability.trace.domain.Processingenterprise;
import com.traceability.trace.service.IProcessingenterpriseService;
import com.traceability.common.utils.poi.ExcelUtil;
import com.traceability.common.core.page.TableDataInfo;

/**
 * 加工公司Controller
 * 
 * @author xulin
 * @date 2025-01-09
 */
@RestController
@RequestMapping("/traceability-trace/processingenterprise")
public class ProcessingenterpriseController extends BaseController
{
    @Autowired
    private IProcessingenterpriseService processingenterpriseService;

    /**
     * 查询加工公司列表
     */
    @PreAuthorize("@ss.hasPermi('traceability-trace:processingenterprise:list')")
    @GetMapping("/list")
    public TableDataInfo list(Processingenterprise processingenterprise)
    {
        startPage();
        List<Processingenterprise> list = processingenterpriseService.selectProcessingenterpriseList(processingenterprise);
        return getDataTable(list);
    }

    /**
     * 导出加工公司列表
     */
    @PreAuthorize("@ss.hasPermi('traceability-trace:processingenterprise:export')")
    @Log(title = "加工公司", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Processingenterprise processingenterprise)
    {
        List<Processingenterprise> list = processingenterpriseService.selectProcessingenterpriseList(processingenterprise);
        ExcelUtil<Processingenterprise> util = new ExcelUtil<Processingenterprise>(Processingenterprise.class);
        util.exportExcel(response, list, "加工公司数据");
    }

    /**
     * 获取加工公司详细信息
     */
    @PreAuthorize("@ss.hasPermi('traceability-trace:processingenterprise:query')")
    @GetMapping(value = "/{enterpriseId}")
    public AjaxResult getInfo(@PathVariable("enterpriseId") Long enterpriseId)
    {
        return success(processingenterpriseService.selectProcessingenterpriseByEnterpriseId(enterpriseId));
    }

    /**
     * 新增加工公司
     */
    @PreAuthorize("@ss.hasPermi('traceability-trace:processingenterprise:add')")
    @Log(title = "加工公司", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Processingenterprise processingenterprise)
    {
        return toAjax(processingenterpriseService.insertProcessingenterprise(processingenterprise));
    }

    /**
     * 修改加工公司
     */
    @PreAuthorize("@ss.hasPermi('traceability-trace:processingenterprise:edit')")
    @Log(title = "加工公司", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Processingenterprise processingenterprise)
    {
        return toAjax(processingenterpriseService.updateProcessingenterprise(processingenterprise));
    }

    /**
     * 删除加工公司
     */
    @PreAuthorize("@ss.hasPermi('traceability-trace:processingenterprise:remove')")
    @Log(title = "加工公司", businessType = BusinessType.DELETE)
	@DeleteMapping("/{enterpriseIds}")
    public AjaxResult remove(@PathVariable Long[] enterpriseIds)
    {
        return toAjax(processingenterpriseService.deleteProcessingenterpriseByEnterpriseIds(enterpriseIds));
    }
}
